package com.ccb.sc.common.modules.member.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccb.sc.common.modules.member.entity.UserThirdAuth;
import com.ccb.sc.common.modules.member.enums.LoginType;
import com.ccb.sc.common.modules.member.mapper.UserThirdAuthMapper;
import org.springframework.stereotype.Service;

/**
 * @author ken
 * @version 1.0
 * @date 2022/11/7 0:32
 */
@Service
public class UserThirdAuthService extends ServiceImpl<UserThirdAuthMapper, UserThirdAuth> {

    public UserThirdAuth findByAuthIdAndLoginType(String oauthId, LoginType loginType) {
        return this.getOne(new QueryWrapper<UserThirdAuth>()
                .lambda()
                .eq(UserThirdAuth::getOauthId, oauthId)
                .eq(UserThirdAuth::getLoginType, loginType)
                .last("limit 1"));
    }

    public UserThirdAuth findByMemberIdAndLoginType(Long memberId, LoginType loginType) {
        return this.getOne(new QueryWrapper<UserThirdAuth>()
                .lambda()
                .eq(UserThirdAuth::getMemberId, memberId)
                .eq(UserThirdAuth::getLoginType, loginType)
                .last("limit 1"));
    }

    public UserThirdAuth findByUnionId(String unionId, LoginType loginType) {
        return this.getOne(new QueryWrapper<UserThirdAuth>()
                .lambda()
                .eq(UserThirdAuth::getUnionId, unionId)
                .eq(UserThirdAuth::getLoginType, loginType)
                .last("limit 1"));
    }

}
